import IndexMenu from '@/assets/menus/home/indexMenu';
import { deepCopyMenus } from '@/utils';

const state = {
  indexMenus: [], // sideBar菜单
};

const mutations = {
  initMenus: (state) => {
    // 深度赋值
    state.indexMenus = deepCopyMenus(IndexMenu);
  },
  hideMenu: (state) => {
    const tmpLen = state.indexMenus.length;
    for (let i = 1; i < tmpLen; i += 1) {
      state.indexMenus[i].hide = true;
    }
    console.log(state.indexMenus);
  },
  showMenu: (state) => {
    const tmpLen = state.indexMenus.length;
    for (let i = 0; i < tmpLen; i += 1) {
      state.indexMenus[i].hide = false;
    }
  },
  // 隐藏下级注册菜单
  hideLevelReg: (state) => {
    const tmpLen = state.indexMenus.length;
    let subArr;
    let tmpSubLen;
    for (let i = 0; i < tmpLen; i += 1) {
      tmpSubLen = state.indexMenus[i].children.length;
      subArr = state.indexMenus[i].children;
      for (let j = 0; j < tmpSubLen; j += 1) {
        if (subArr[j].hide) {
          subArr[j].hide = true;
          console.log('隐藏操作', subArr);
          break;
        }
      }
    }
  },
  // 显示下级注册菜单
  showLevelReg: (state) => {
    const tmpLen = state.indexMenus.length;
    let subArr;
    let tmpSubLen;
    for (let i = 0; i < tmpLen; i += 1) {
      tmpSubLen = state.indexMenus[i].children.length;
      subArr = state.indexMenus[i].children;
      for (let j = 0; j < tmpSubLen; j += 1) {
        if (subArr[j].hide) {
          subArr[j].hide = false;
          console.log('显示操作', subArr);
          break;
        }
      }
    }
  },
  // 滴滴滴
  showCourseUpload: (state, arg) => {
    const tmpLen = state.indexMenus.length;
    let subArr;
    let tmpSubLen;
    for (let i = 0; i < tmpLen; i += 1) {
      tmpSubLen = state.indexMenus[i].children.length;
      subArr = state.indexMenus[i].children;
      for (let j = 0; j < tmpSubLen; j += 1) {
        if (subArr[j].id === 93) {
          subArr[j].hide = arg;
          console.log(arg ? '隐藏上传课程' : '展示上传课程');
          break;
        }
      }
    }
  },
};

const actions = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
